import DatePicker from "components/antd-compatible/date-picker";
import React from 'react';
import {messages} from "share/common";
import config from "config";
import Selector from 'components/selector'
import {Select} from "antd/lib/index";
;

const Option = Select.Option;

export default {
  getSearchForm() {
    let month = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map(item => {
      return {value: item, label: messages('finance-7.key1',{arg1: item})/*{arg1}月*/}
    });
    let year = [];
    let date = new Date();
    for (let i = date.getFullYear(); i >= 2010; i--) {
      year.push({value: i, label: i});
    }
    return [
      {
        component: 'Chooser',
        id: 'statisticByCompanyList',
        label: messages('finance-7.key2')/*公司*/,
        props: {
          type: 'permission_company',
          labelKey: 'name',
          valueKey: 'companyOID'
        },
        parser: value => ({
          statisticByCompanyList: value && value.length ? value.map(item => item.companyOID) : null
        }),
      },
      {
        component: 'Select',
        id: 'statisticByYear',
        props: {
          style: {width: '100%'},
        },
        label: messages('finance-7.key3')/*年份*/,
        children: year.map(item => <Option key={item.value}>{item.label}</Option>),
        initialValue: date.getFullYear() + '',
        tagParser: (value) => this.tagParseFormat(value, year),
      },
      {
        component: 'Select',
        id: 'startMonth',
        props: {
          style: {width: '100%'},
        },
        decorator: {
          rules: [{
            required: true,
            message: messages('finance-7.key4')/*必填*/
          }]
        },
        label: messages('finance-7.key5')/*开始月份*/,
        children: month.map(item => <Option key={item.value}>{item.label}</Option>),
        initialValue: '1',
        tagParser: (value) => this.tagParseFormat(value, month),
      },
      {
        component: 'Select',
        id: 'endMonth',
        decorator: {
          rules: [{
            required: true,
            message: messages('finance-7.key4')/*必填*/
          }]
        },
        props: {
          style: {width: '100%'},
        },
        label: messages('finance-7.key6')/*结束月份*/,
        children: month.map(item => <Option key={item.value}>{item.label}</Option>),
        initialValue: '12',
        tagParser: (value) => this.tagParseFormat(value, month),
      },
    ]
  },
  tagParseFormat(value, arr) {
    let label = '';
    arr.map(item => {
      if (item.value + '' === value) {
        label = item.label;
      }
    });
    return label;
  },
}
